<?php

namespace app\model;

use think\facade\Cache;
use think\Model;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

class SysRegion extends Model
{
    public function cityTree()
    {
        $data = $this->with(['children'=>function ($query) {
            $query->with(['children']);
        }])->where('parent', 0)->cache("zssf_values_city_tree", 7 * 24 * 60 * 60)->select()->toArray();
        return $data;
    }

    public function children(): HasMany
    {
        return $this->hasMany(self::class, 'parent', 'adcode');
    }
}
